package a10_动态规划;

/**
 * <p>
 * a17_一和零复习1
 * </p>
 *
 * @author flyduck
 * @since 2025/2/13
 */
public class a17_一和零复习1 {
    //dp[i][j]:装满容量为i个m和j个n的背包最多物品数量
    //递推公式：dp[i][j] = Math.max(dp[i][j],dp[i-x][j-y] + 1)
    public int findMaxForm(String[] strs, int m, int n) {
        int[][] dp = new int[m+1][n+1];
        dp[0][0] = 0;

        for (String str : strs) {
            int x = 0;
            int y = 0;
            for (char c : str.toCharArray()) {
                if(c == '0'){
                    x++;
                }else {
                    y++;
                }
            }

            for (int i = m; i >= x; i--) {
                for (int j = n; j >= y; j--) {
                    dp[i][j] = Math.max(dp[i][j],dp[i-x][j-y] + 1);
                }
            }
        }

        return dp[m][n];
    }
}
